<extend name="Layout:layout_edit" />
<block name="body_content_block">
    <form action="{:AddonU('Queue/seat_edit_save')}" method="post" data-success-fn="show_reload_tip()">
        <table>
            <tr>
                <th>队列号码：</th><td>
                    <input type="text" class="easyui-textbox" name="extension" value="{$data.extension}" readonly="readonly"/>
                </td></tr>
            <tr>
            <th style="vertical-align: top">座席号码：</th><td>
                    <textarea name="members" cols="20" rows="16">{$data.members}</textarea>
                    <div style="color:#F00;">说明：<br />1.多个号码,每个号码一行<br />2.如果是远程座席号码,请直接输入座席号码</div>
                </td></tr>
                <tr>
                    <th>&nbsp;</th><td>
                        <select id="members-picker" title="请选择分机号" data-url="{:AddonU('Extension/get_extension_json')}"></select>
                    </td></tr>
                <tr>
                    <th>远程座席中继：</th><td>
                        <select name="trunkName" title="请选择中继名称" data-url="{:AddonU('Trunk/get_json')}" data-value="{$data.trunkName}"></select>
                        <input type="hidden" name="regMode" value="{$data.regMode}"/>
                    </td></tr>
        </table>
        <input type='hidden' name='id' value='{$data.id}'/>
        <input type="hidden" name="siteID" value="{$data.siteID}" />
        <input type="hidden" name="oldmembers" value="{$data.members}" />
    </form>
</block>
<block name="body_after_block">
    <script>
        item_form.resize_owner_dialog({width:500});
        afterSiteID();
        function afterSiteID() {
            var val = $('input[name="siteID"]').val();
            if (!val) {
                return;
            }
            ajax_load_options({selector: '#members-picker', queryParams: {siteID: val}, def_option: '选择分机号'});
            ajax_load_options({selector:'select[name="trunkName"]', queryParams:{siteID:val},def_option: '请选择中继名称'});
        }
        $('#members-picker').change(function () {
            var vals = $('textarea[name="members"]').val();
            var val = $(this).val();
            if (vals.length > 0 && (vals.indexOf("\n" + val) > -1 || vals.indexOf(val + "\n") > -1)) {
                return;
            }
            $('textarea[name="members"]').val(val + "\n" + vals);
        })
        $('#btn-submit').click(function () {
            if ($('textarea[name="members"]').val().length > 0 && $('select[name="trunkName"]').val().length == 0) {
                alert('远程座席中继未选择');
                return false;
            }
            return true;
        })
    </script>
</block>